<?php
/**
* Admin Deposit Controller
*
* This handles all AJAX requests from the Admin GUI Deposit Configuration page.
* These methods will create an AJAX response containing JSON data. The JSON
* data is read by the JS code and rendered into interface.
*
* @access 	public
* @author 	Rob, Valentin
* @copyright	ResMania 2009 all rights reserved.
* @version	1.0
* @link		http://developer.resmania.com/api
* @since  	05-2009
*/
class RM_Admin_DepositController extends RM_Controller
{
    /**
     * This loads the deposit configuration, the data is retrieved using the
     * RM_Deposit class
     *
     * @return 	json    json array information containing deposit information
     */
    public function configJsonAction(){

        $depositModel = new RM_Deposit;
        $settings = $depositModel->getSettings()->toArray();

        return array(
            'data' => array('settings' => $settings)
        );
    }

    /**
     * This saves the deposit settings from the plugin->deposit setting page
     *
     * @return 	json    success value true/false
     */
    public function updateJsonAction(){
        $settings = $this->_getParam('rm_pages_plugins_deposit');

        // Create the deposit object, RM_Deposit extends RM_Model so we can use
        // methods that this inherits such as find, save to update the DB.
        $depositModel = new RM_Deposit;

        $settingsDB = $depositModel->getSettings();
        foreach ($settings as $key => $value) {
            $settingsDB->$key = $value;
        }
        $settingsDB->save();

        // return a state to the GUI so that the saving message is removed etc.
        // look edit.js->RM.Pages.Functions.plugins_deposit_save for the success,
        // failure handling
        return array(
            'data' => array('success' => true)
        );

    }

}